/**
 * Created by zhangshun on 2018/7/29.
 */
var MD5 = require("md5.js");
/**时间戳*/
function getTimeStamp(){
    var timestamp=new Date().getTime();
    var timestampstring = timestamp.toString();//一定要转换字符串
    return timestampstring;
}
/**随机字符串*/
function getNonceStr(){
    var $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var maxPos = $chars.length;
    var noceStr = "";
    for (var i = 0; i < 32; i++) {
        noceStr += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return noceStr;
}
/**签名方式*/
function getMD5SignType(){
    return "MD5";
}

/**微信支付签名
 * @param appId 小程序appId*/
function getSign(appId,nonceStr,timeStamp,prepayId,signType,key){
    //第一步，对所有需要传入的参数加上appkey作一次key＝value字典序的排序
  var keyvaluestring = "appId=" + appId + "&nonceStr=" + nonceStr +"&package=prepay_id="+prepayId+"&signType="+signType+"&timeStamp="+timeStamp+"&key="+key;
  var sign = MD5.MD5(keyvaluestring).toString();
    return sign;
}
module.exports = {
  getTimeStamp: getTimeStamp,
  getNonceStr: getNonceStr,
  getMD5SignType: getMD5SignType,
  getSign: getSign
}
